function HomeCtrl (){
    var indexAction = function(){}();
}

function AccountingCtrl ($scope,$routeParams,utils,dateUtils,$timeout,taffy){

    var year = $routeParams.year;
    var month = $routeParams.month;

    if($.trim(month) == ""){
        month = "january";
    }

    if(!dateUtils.isValidYear(year) || !dateUtils.isValidMonth(month)){
        utils.notFound();
    }

    $scope.year = year;
    $scope.month = month;


    var accountings = taffy.open("accountings");
    var categories = taffy.open("categories");
    $scope.accountings = taffy.open("accountings")({"date":{"left":year+"-"+dateUtils.getMonthNumber(month)}}).join(categories,['categoryId','id']).order("date asc").get();
    $scope.type = "recipe";
    $scope.recipes = categories({"type":"recipe"}).order("name asc").get();
    $scope.expenses = categories({"type":"expense"}).order("name asc").get();


    $scope.add = function(){
       dateUtils.getMonthNumber($scope.month);
        if($scope.rowForm.$valid){
            var accountings = taffy.open("accountings");
            accountings.insert({
                "id" : accountings.nextId(),
                "label" : $scope.row.label,
                "amount" : $scope.row.amount,
                "date" : dateUtils.toSQLFormat($scope.year,dateUtils.getMonthNumber($scope.month),$scope.row.day),
                "categoryId" : parseInt($scope.row.categoryId)
            });

            $scope.row = null;
            $scope.accountings = accountings({"date":{"left":year+"-"+dateUtils.getMonthNumber(month)}}).join(categories,['categoryId','id']).order("date asc").get();
            $timeout(function(){
                $("form[name=rowForm] :input:first").focus();
                tableScrollable.init();
            });
        }
    };


    $timeout(function(){
        tableScrollable.init();

        $('#rowModal').on('hide', function () {
            $scope.row = null;
            $scope.$apply();
        });

        $('#rowModal').on('shown', function () {
            $("form[name=rowForm] :input:first").focus();
        });

        $(document).keypress(function(e){
            var code = (e.keyCode ? e.keyCode : e.which);
            if(code == 43) {
                $('#rowModal').modal("show");
            }
        });
    });




}